/**
 * Created by Dalyn on 2017/2/28.
 */
import React from "react";
import './css/TicklingList.css'
import {hashHistory} from 'react-router';
import TicklingListMutation from './mutation/TicklingListMutation'
import SuggestItem from "./SuggestItem"
import Relay from "react-relay";
import Pagination from "./Pagination"
import ReactKey from "../../util/ReactKey"
import Addstaff from "./Addstaff";
import Util from "../../util/Util";
/*信息列表*/

/*导出组件*/
export default class TicklingList extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            userName: '',
            enterpriseName:'',
            suggestData: [],
            totalresult:'',
            defaultValue: '',
        };
        this.pageNum = 1;
        this.pageSize = 10;
        this.status = "";
    }

    //asdasds
    componentWillMount() {
        this.style = {
            detail_content: {
                height: 735,
                marginTop:10
            },
            title_1: {
                display: 'inline-block',
                width: 65,
                height: 38,
                paddingLeft: '10px',
                lineHeight: '36px',
            },
            title_11: {
                fontFamily: '新宋体',
                fontWeight: '600',
                color: '#333',
                fontSize: '14px',
                paddingLeft: '5px'
            },
            title_12: {
                width: 13,
                height: 13,
                borderRadius: '2px',
                border: '1px solid #666'
            },
            title_2: {
                display: 'inline-block',
                width: 119,
                height: 38,
                textAlign: 'center',
                lineHeight: '36px',
                fontFamily: '新宋体',
                color: '#333',
                fontSize: '14px'
            },
            title_3: {
                display: 'inline-block',
                width: 130,
                height: 38,
                textAlign: 'center',
                lineHeight: '36px',
                fontFamily: '新宋体',
                color: '#333',
                fontSize: '14px'
            },
            title_4: {
                display: 'inline-block',
                width: 130,
                height: 38,
                textAlign: 'center',
                lineHeight: '36px',
                fontFamily: '新宋体',
                color: '#333',
                fontSize: '14px'
            },
            title_5: {
                display: 'inline-block',
                width: 180,
                height: 38,
                textAlign: 'center',
                lineHeight: '36px',
                fontFamily: '新宋体',
                color: '#333',
                fontSize: '14px'
            },
            title_6: {
                display: 'inline-block',
                width: 196,
                height: 38,
                textAlign: 'center',
                lineHeight: '36px',
                fontFamily: '新宋体',
                color: '#333',
                fontSize: '14px'
            },
            title_7: {
                display: 'inline-block',
                width: 200,
                height: 38,
                textAlign: 'center',
                lineHeight: '36px'
            },
            title_71: {
                fontFamily: '新宋体',
                color: '#333',
                fontSize: '14px'
            },
            page_ensure: {
                width: '39px',
                height: '19px',
                backgroundColor: "white",
                border: '1px solid #e7e6e6',
                borderRadius: '2px',
                color: "#999"
            }
        }
        this.getTicklingList(1,10);
    }



    getTicklingList(pageNum, pageSize) {
        Relay.Store.commitUpdate(
            new TicklingListMutation({
                //放传给后台参数的地方
                pageNum: pageNum,
                pageSize: pageSize,
            }),
            {
                onFailure: () => {
                },
                onSuccess: (response) => {
                    let data = response.getSuggestList.getSuggestList;
                    let errorCode=response.getSuggestList.getSuggestList.errorCode;
                    if(errorCode=="0"){
                        this.setState({
                            totalresult: data.totalResult,
                            suggestData:data.suggestList
                        })
                    }
                }
            });

    }


    replyInfo(uid) {
        this.refs.addstaff.setState({
            visible: true,
            conname: '确定',
            title: '意见回复'
        }, () => {
            this.refs.addstaff.setState({
                uid: uid
            })
            this.refs.addstaff.initHit();
            this.refs.addstaff.refs.content.setState({text:""})
        });
    }
    //
    // createPart() {
    //     hashHistory.push('/CreateCompany')
    // }

    onSure(size, num) {
        this.getTicklingList(size, num)
    }
    render() {
        this.datasize = this.state.suggestData.length;
        return (
            <div>
                <div style={this.style.detail_content}>
                    <table className="settle_rec_table" style={{borderCollapse: "collapse"}}>
                        <colgroup>
                            <col  style={{width:"70%", minWidth:"20%"}}/>
                            <col  style={{width:"10%", minWidth:"20%"}}/>
                            <col  style={{width:"10%", minWidth:"20%"}}/>
                            <col  style={{width:"10%", minWidth:"20%"}}/>
                        </colgroup>
                        <thead>
                        <tr style={{height: "40px", background: "#f2f2f2"}}>
                            {/*<AllCheckbox handleclick={this.handleclick.bind(this)} ref={'allcheck'}/>*/}
                            <th style={{border: "1px solid #e7e7e7"}}>意见反馈</th>
                            <th style={{border: "1px solid #e7e7e7"}}>状态</th>
                            <th style={{border: "1px solid #e7e7e7"}}>反馈时间</th>
                            <th style={!Util.authorityCheck("ticking") ? {display: 'none', border: "1px solid #ccc"} :{width: 119, border: "1px solid #e7e7e7"}}>回复</th>
                        </tr>
                        </thead>
                        <tbody style={{height: "40px", background :"#ffffff"}}>
                        {
                            this.state.suggestData.map((ele, index) => {
                                    return <SuggestItem ele={ele} key={ ReactKey.key } ref={'pitem' + index}
                                                      index={index}  replyInfo={this.replyInfo.bind(this)} getTicklingList={this.getTicklingList.bind(this)}/>
                                }
                            )
                        }
                        </tbody>
                    </table>

                    {/*循环输出详细的人员数据*/}


                    <Pagination eachSize={10} dataSize={this.state.totalresult} onSure={this.onSure.bind(this)}
                                ref={'pagination'}/>

                    {/*弹窗*/}
                    <Addstaff ref={'addstaff'} getTicklingList={this.getTicklingList.bind(this)}/>

                </div>
            </div>
        )
    }
}
